package cn.whale.kill.mq.callback;

import cn.whale.basic.utils.JSONResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
@Slf4j
@Transactional
public class KillMsgConfirmCallback implements RabbitTemplate.ConfirmCallback, RabbitTemplate.ReturnCallback {


    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        log.debug("PayMsgConfirmCallback 消息投递回调，ACK={},cause={},correlationData={}",ack,cause,correlationData);
        if(!ack){
            //String correlationDataId = correlationData.getId();
            log.error("秒杀消息发布到Redis失败{}",cause);
        }
    }

    @Override
    public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        log.debug("消息投递到队列失败message={},replyText={}",message,replyText);
        String correlationDataId = message.getMessageProperties().getHeaders().get("spring_returned_message_correlation").toString();
        log.error("修改支付结果MQ日志消息ID{}",correlationDataId);
    }


}
